<?php

include_once dirname(__FILE__).'/helpers.php';

function pr($var, $dump=0) {
	echo '<pre>';
	$dump ? var_dump($var) : print_r($var);
	echo '</pre>';
}

function __autoload($class) {
	global $CLASS_PATHS;
	if (array_key_exists($class, $CLASS_PATHS)) {
		include_once $CLASS_PATHS[$class];
	}
}

$CLASS_PATHS = array();
function find_classes($dir) {
	global $CLASS_PATHS;
	
	if (is_dir($dir)) {
		$dh = opendir($dir);
		while (($file = readdir($dh)) !== false) {
			if ($file != '.' && $file != '..') {
				if (is_file($dir.$file) &&
					is_readable($dir.$file) &&
					substr($file, -4) == '.php') {
					$class = substr($file, 0, strlen($file)-4);
					$CLASS_PATHS[$class] = $dir.$file;
				} elseif (is_dir($dir.$file)) {
					find_classes($dir.$file.'/');
				}
			}
		}
	} else {
		throw new Exception($dir.' isn\'t directory');
	}
}
find_classes(realpath(dirname(__FILE__).'/../lib').'/');

Log::turn_on();
